/**
*手机终端控制 zoe.C
*/

var mobileMc = {
	appendCss:function(){
		var divO= document.createElement('STYLE');
			  divO.innerHTML = '.min_background {position: absolute;left: 0%;top: 0%;-webkit-perspective: 0;display: block;	-webkit-animation-name: boxEnter;-webkit-transform-origin: bottom left;'
								+	 'background-color:#5F686D;background-image:url(/EMSP_CMS/uploadImages/0.png) no-repeat;color:#ffffff;opacity:1;background-size: 100% 100%;}'
								+	 '.article{width: 70%;height: 62%;position: absolute;left: 27%;top: 26.5%;text-indent: 1em;overflow:scroll;overflow-x:hidden;overflow-y: auto;font-size:26px;background-attachment:fixed;color:#FFFFFF;z-index:200;}'					
								+	 '.column_path{left:27%;top:10%;width:763px;height:30px;font-size:24px;color:#FFFFFF;z-index:12;}';
			  document.documentElement.appendChild(divO);
	},
	validata:function(){
		var res = false;
		var p = window.parent;
		console.debug(p);
		if(p != undefined && p.terminal != undefined && p.terminal == "mobile"){
			 res = true;
		}
		return res;
	},
	overwrite:function(){
		if(this.validata()){
			this.appendCss();
			var divArr = document.getElementsByTagName("div"),
				marArr = document.getElementsByTagName("marquee"),
				butArr = document.getElementsByTagName("button"),
				imgArr = document.getElementsByTagName("img"),
				columnArr = [],
				pageDivArr = [];
				
			/*控制div*/
			for(var i = 0;i < divArr.length; i ++){
				if(divArr[i].getAttribute('cms_class') == 'CmsTemplate' || divArr[i].getAttribute('cms_class') ==  'CmsComp_Image_BkgImage'){
					divArr[i].style.overflow = 'hidden';
					divArr[i].style.backgroundSize = '100% 100% ';
					divArr[i].style.width = "100%";
					divArr[i].style.height = "100%";
				}else if(divArr[i].getAttribute('cms_class') ==  'CmsComp_Text_Content'){
					var ar_div = document.createElement('div');
						  ar_div.className = 'article';
						  ar_div.setAttribute("id","cms_mobile_content");
						  ar_div.innerHTML =  divArr[i].innerHTML;
						
					divArr[i].parentNode.removeChild(divArr[i]);
					document.getElementsByTagName("body")[0].appendChild(ar_div);
				}else if(divArr[i].getAttribute("cms_class") == "CmsComp_Col_Path"){
					columnArr.push(divArr[i]);
				}else if(divArr[i].id.indexOf('CMS_Content_') != -1){
					pageDivArr.push(divArr[i]);
				}else if(divArr[i].getAttribute("cms_class") == "CmsComp_Ctrl_Pagination"){
					divArr[i].parentNode.removeChild(divArr[i]);
				}
			}
			/*分页模版处理*/
			var pageContent = '';
			for(var p =0;p < pageDivArr.length; p++){
				pageContent += pageDivArr[p].innerHTML;
				pageDivArr[p].parentNode.removeChild(pageDivArr[p]);
			}
			if(pageContent != '')
			    document.getElementById('cms_mobile_content').innerHTML = pageContent;
			
			/*控制栏目*/
			for(var c = 0;c < columnArr.length; c++){
				 if(c == 0){
					 columnArr[c].style.left = "28%";
					 columnArr[c].style.top = "10%";
					 columnArr[c].style.height = "7.6%";
				 }
				 if(c == 1){
					columnArr[c].style.left = "7.8%";
					columnArr[c].style.top = "17%";
					columnArr[c].style.height = "7.6%";
				 }
			}
			
			/*控制marquee*/
			for(var j = 0;j < marArr.length; j++){
				if(marArr[j].getAttribute('cms_class') == 'CmsComp_Layout_Marquee'){
					var ar_div = document.createElement('div');
						ar_div.className = 'article';
						ar_div.innerHTML = marArr[j].innerHTML;
					marArr[j].parentNode.removeChild(marArr[j]);
					document.getElementsByTagName("body")[0].appendChild(ar_div);
				}
			}
			
			/*控制button*/
			for(var n = 0;n < butArr.length;n ++){
				butArr[n].parentNode.removeChild(butArr[n]);
			}
			
			/*广告图片*/
			for(var m = 0; m < imgArr.length; m++){
				if(imgArr[m].getAttribute('cms_class') == 'CmsComp_Image_Static'){
					imgArr[m].style.left = '3.5%';
					imgArr[m].style.top = '26%';
					imgArr[m].style.width = '20.6%';
					imgArr[m].style.height = '62%';
				}
			}
		}
	}
};

